#!/usr/bin/perl

use strict;
use warnings;
use Socket;

sub reconstruct_full_url
{
	if (!exists($ENV{'HTTP_HOST'}))
	{
		# then it wasnt from the website and you're debugging from command line
		return '';
	}
	my $proto = $ENV{'SERVER_PROTOCOL'};
	$proto = lc(substr($proto, 0, index($proto, '/')));
	my $host = $ENV{'HTTP_HOST'};
	my $port = $ENV{'SERVER_PORT'};
	# match protocol to port, but for now hack by assuming only http and 80
	$port = ($port == 80 ? "" : ":$port");
	my $request_uri = $ENV{'REQUEST_URI'};
	
	return "$proto://$host$port$request_uri";
}


if (!exists($ENV{'REMOTE_HOST'}))
{
	my $iaddr = inet_aton($ENV{'REMOTE_ADDR'});
	$ENV{'REMOTE_HOST'} = gethostbyaddr($iaddr, AF_INET);
}

=wut
if (!exists($ENV{'HTTP_REFERER'}))
{
	$ENV{'HTTP_REFERER'} = '';
}
=cut

1;
